
-- --------------------------------------------------
-- Entity Designer DDL Script for SQL Server 2005, 2008, and Azure
-- --------------------------------------------------
-- Date Created: 02/28/2015 14:35:07
-- Generated from EDMX file: D:\mcgrady\workspaces\TFS25\Roy\Roy.Data\RoyDB.edmx
-- --------------------------------------------------

SET QUOTED_IDENTIFIER OFF;
GO
USE [RoyDB];
GO
IF SCHEMA_ID(N'dbo') IS NULL EXECUTE(N'CREATE SCHEMA [dbo]');
GO

-- --------------------------------------------------
-- Dropping existing FOREIGN KEY constraints
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[FK_UserUserOrg]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[SM_UserOrg] DROP CONSTRAINT [FK_UserUserOrg];
GO
IF OBJECT_ID(N'[dbo].[FK_OrgUserOrg]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[SM_UserOrg] DROP CONSTRAINT [FK_OrgUserOrg];
GO

-- --------------------------------------------------
-- Dropping existing tables
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[SM_User]', 'U') IS NOT NULL
    DROP TABLE [dbo].[SM_User];
GO
IF OBJECT_ID(N'[dbo].[SM_Org]', 'U') IS NOT NULL
    DROP TABLE [dbo].[SM_Org];
GO
IF OBJECT_ID(N'[dbo].[SM_UserOrg]', 'U') IS NOT NULL
    DROP TABLE [dbo].[SM_UserOrg];
GO

-- --------------------------------------------------
-- Creating all tables
-- --------------------------------------------------

-- Creating table 'SM_User'
CREATE TABLE [dbo].[SM_User] (
    [ID] int IDENTITY(1,1) NOT NULL,
    [Code] nvarchar(20)  NULL,
    [UserID] nvarchar(20)  NOT NULL,
    [Password] nvarchar(20)  NOT NULL,
    [Name] nvarchar(20)  NOT NULL,
    [Gender] tinyint  NULL,
    [Email] nvarchar(20)  NULL,
    [Phone] nvarchar(20)  NULL,
    [IsEnabled] bit  NOT NULL,
    [IsChangePwd] bit  NOT NULL,
    [LoginCount] int  NOT NULL,
    [LastLoginTime] datetime  NULL,
    [CreateTime] datetime  NULL,
    [CreatedBy] nvarchar(30)  NULL,
    [Description] nvarchar(max)  NULL
);
GO

-- Creating table 'SM_Org'
CREATE TABLE [dbo].[SM_Org] (
    [ID] int IDENTITY(1,1) NOT NULL,
    [Code] nvarchar(30)  NULL,
    [Name] nvarchar(30)  NULL,
    [ParentId] int  NOT NULL,
    [Sort] int  NULL,
    [IsEnabled] bit  NULL,
    [CreateTime] datetime  NULL,
    [CreatedBy] nvarchar(30)  NULL,
    [Description] nvarchar(max)  NULL
);
GO

-- Creating table 'SM_UserOrg'
CREATE TABLE [dbo].[SM_UserOrg] (
    [UserId] int  NOT NULL,
    [OrgId] int  NOT NULL
);
GO

-- Creating table 'SM_Role'
CREATE TABLE [dbo].[SM_Role] (
    [ID] int IDENTITY(1,1) NOT NULL,
    [Code] nvarchar(30)  NULL,
    [Name] nvarchar(30)  NOT NULL,
    [CreateTime] datetime  NOT NULL,
    [CreatedBy] nvarchar(30)  NULL,
    [Description] nvarchar(max)  NULL
);
GO

-- Creating table 'SM_UserRole'
CREATE TABLE [dbo].[SM_UserRole] (
    [UserId] int  NOT NULL,
    [RoleId] int  NOT NULL
);
GO

-- Creating table 'SM_Menu'
CREATE TABLE [dbo].[SM_Menu] (
    [ID] int IDENTITY(1,1) NOT NULL,
    [Code] nvarchar(30)  NULL,
    [Name] nvarchar(30)  NOT NULL,
    [ParentId] int  NOT NULL,
    [Sort] int  NULL,
    [URL] nvarchar(50)  NULL,
    [Icon] nvarchar(50)  NULL,
    [ControllerName] nvarchar(50)  NULL,
    [CreateTime] datetime  NULL,
    [CreatedBy] nvarchar(30)  NULL,
    [Description] nvarchar(max)  NULL
);
GO

-- Creating table 'SM_Button'
CREATE TABLE [dbo].[SM_Button] (
    [ID] int IDENTITY(1,1) NOT NULL,
    [Code] nvarchar(30)  NULL,
    [Name] nvarchar(30)  NOT NULL,
    [Icon] nvarchar(30)  NULL,
    [Sort] int  NULL,
    [URL] nvarchar(50)  NULL,
    [CreateTime] datetime  NULL,
    [CreatedBy] nvarchar(30)  NULL,
    [Description] nvarchar(max)  NULL
);
GO

-- Creating table 'SM_MenuButton'
CREATE TABLE [dbo].[SM_MenuButton] (
    [MenuId] int  NOT NULL,
    [ButtonId] int  NOT NULL
);
GO

-- Creating table 'SM_RoleMenuButton'
CREATE TABLE [dbo].[SM_RoleMenuButton] (
    [RoleId] int  NOT NULL,
    [MenuId] int  NOT NULL,
    [ButtonId] int  NOT NULL
);
GO

-- Creating table 'SM_LoginLog'
CREATE TABLE [dbo].[SM_LoginLog] (
    [ID] int IDENTITY(1,1) NOT NULL,
    [UserId] nvarchar(30)  NULL,
    [UserName] nvarchar(30)  NULL,
    [IP] nvarchar(30)  NULL,
    [HostName] nvarchar(30)  NULL,
    [LoginTime] datetime  NULL,
    [LoginStatus] tinyint  NOT NULL,
    [Description] nvarchar(max)  NULL
);
GO

-- Creating table 'SM_OperationLog'
CREATE TABLE [dbo].[SM_OperationLog] (
    [ID] int IDENTITY(1,1) NOT NULL,
    [Operator] nvarchar(30)  NULL,
    [IP] nvarchar(30)  NULL,
    [OperateType] tinyint  NULL,
    [OperateTime] datetime  NULL,
    [Description] nvarchar(max)  NULL
);
GO

-- Creating table 'SM_ErrorLog'
CREATE TABLE [dbo].[SM_ErrorLog] (
    [ID] int IDENTITY(1,1) NOT NULL,
    [URL] nvarchar(max)  NULL
);
GO

-- --------------------------------------------------
-- Creating all PRIMARY KEY constraints
-- --------------------------------------------------

-- Creating primary key on [ID] in table 'SM_User'
ALTER TABLE [dbo].[SM_User]
ADD CONSTRAINT [PK_SM_User]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [ID] in table 'SM_Org'
ALTER TABLE [dbo].[SM_Org]
ADD CONSTRAINT [PK_SM_Org]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [UserId], [OrgId] in table 'SM_UserOrg'
ALTER TABLE [dbo].[SM_UserOrg]
ADD CONSTRAINT [PK_SM_UserOrg]
    PRIMARY KEY NONCLUSTERED ([UserId], [OrgId] ASC);
GO

-- Creating primary key on [ID] in table 'SM_Role'
ALTER TABLE [dbo].[SM_Role]
ADD CONSTRAINT [PK_SM_Role]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [UserId], [RoleId] in table 'SM_UserRole'
ALTER TABLE [dbo].[SM_UserRole]
ADD CONSTRAINT [PK_SM_UserRole]
    PRIMARY KEY NONCLUSTERED ([UserId], [RoleId] ASC);
GO

-- Creating primary key on [ID] in table 'SM_Menu'
ALTER TABLE [dbo].[SM_Menu]
ADD CONSTRAINT [PK_SM_Menu]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [ID] in table 'SM_Button'
ALTER TABLE [dbo].[SM_Button]
ADD CONSTRAINT [PK_SM_Button]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [MenuId], [ButtonId] in table 'SM_MenuButton'
ALTER TABLE [dbo].[SM_MenuButton]
ADD CONSTRAINT [PK_SM_MenuButton]
    PRIMARY KEY NONCLUSTERED ([MenuId], [ButtonId] ASC);
GO

-- Creating primary key on [RoleId], [MenuId], [ButtonId] in table 'SM_RoleMenuButton'
ALTER TABLE [dbo].[SM_RoleMenuButton]
ADD CONSTRAINT [PK_SM_RoleMenuButton]
    PRIMARY KEY CLUSTERED ([RoleId], [MenuId], [ButtonId] ASC);
GO

-- Creating primary key on [ID] in table 'SM_LoginLog'
ALTER TABLE [dbo].[SM_LoginLog]
ADD CONSTRAINT [PK_SM_LoginLog]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [ID] in table 'SM_OperationLog'
ALTER TABLE [dbo].[SM_OperationLog]
ADD CONSTRAINT [PK_SM_OperationLog]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [ID] in table 'SM_ErrorLog'
ALTER TABLE [dbo].[SM_ErrorLog]
ADD CONSTRAINT [PK_SM_ErrorLog]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO










-- --------------------------------------------------
-- Creating all Property by http://www.yongfa365.com/
-- --------------------------------------------------

------  table 'SM_User'



------  table 'SM_Org'



------  table 'SM_UserOrg'



------  table 'SM_Role'



------  table 'SM_UserRole'



------  table 'SM_Menu'



------  table 'SM_Button'



------  table 'SM_MenuButton'



------  table 'SM_RoleMenuButton'



------  table 'SM_LoginLog'



------  table 'SM_OperationLog'



------  table 'SM_ErrorLog'




-- --------------------------------------------------
-- Script has ended
-- --------------------------------------------------


